
import { gif } from "./TS/BASE/spineANDgif/gif";
import GeZiManager from "./TS/Manager/GeZiManager";
import TNanager from "./TS/Manager/TNanager";

import turn from "./TS/game/time/turn";
import xgcol from "./xgmove";

const {ccclass, property} = cc._decorator;

@ccclass
export default class nodecol extends cc.Component {

    allnode:cc.Node[]=[]
    play_lun_animation:any
    @property(cc.SpriteFrame)
    picture: cc.SpriteFrame[] = [];
    @property(Number)
    move_velocity:number=0.7
    @property(Number)
    disappear_velocity:number=0.5
    @property(Number)
    spawn_positionx:number
    @property(Number)
    spawn_positiony:number
   B:boolean=false;
   timer: number = 0; // 计时器
   isPaused: boolean = false; // 是否暂停

   
   start () 
    {
        //初始化数字
        this.play_lun_animation=this.getComponent(gif)
        this.play_lun_animation.timeArray=[80,80,70,45,70,60,60,60,100,80,80,70,45]
        for(let i=0;i<=5;i++)
        {
            if(i==0)
            {
                let tnode=this.node.getChildByName((6).toString())
                tnode.opacity=0
                this.allnode.push(tnode)
                tnode.getComponent(cc.Sprite).spriteFrame=this.picture[5]
                continue
            }
            let tnode=this.node.getChildByName((i).toString())
            tnode.getComponent(cc.Sprite).spriteFrame=this.picture[i-1]
            if(i>=4) 
            {
                tnode.opacity=0
            }
            this.allnode.push(tnode)
            if(i==5)
            {
                //右边出生的位置
                this.spawn_positionx=tnode.position.x
                this.spawn_positiony=tnode.position.y
            }
        }
    }

    getRandomInt(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }
mm(){

if(this.B){setTimeout(() => {
    this.mm();
},600);}else{this.B=true;this.move()}

}

    move()
    {

        let firstnode:cc.Node=null
        let tstring=this.allnode[2].getComponent(cc.RichText).string

        if(tstring=="6")
        {
            this.getComponent(gif).moveToNextFrame(5,8,0)
            
            if(turn.day>=4){   this.node.getChildByName("xgcol").getComponent(xgcol).richtextmove(turn.round%2)}
            else{this.node.getChildByName("xgcol").getComponent(xgcol).richtextmove(GeZiManager.TNJM[turn.round+2])}
            setTimeout(()=>{this.getComponent(gif).moveToNextFrame(9,11,0)}, 350);
            setTimeout(()=>{this.animation_play()}, 350);
            setTimeout(()=>{this.getComponent(gif).changeF(0,1)}, 700);
        }
        //轮盘移动
        if(tstring=="2"||tstring=="4")
        {
            
            setTimeout(() => {
                this.getComponent(gif).moveToNextFrame(9,11,0)
                setTimeout(()=>{this.getComponent(gif).changeF(0,1)},300);
            },100);
           
            this.animation_play()
        }
        else if(tstring=="1"||tstring=="3"||tstring=="5")
        {
           setTimeout(() => {
           //
           }, 80); 
            this.animation_play()
        }
        setTimeout(() => {
            this.B=false
        }, 1100);
    }

    animation_play()
    {

      
        let firstnode:cc.Node=null
        //数字移动
        for(let i=0;i<6;i++)
            {
                let tnode=this.allnode[i]
                if(i==0)
                {
                    //6左边出去,调整透明度,同时生成新的6在最右边
                    cc.tween(tnode).to(this.disappear_velocity+0.3, { opacity: 0}).call(() => {
                        firstnode=tnode
                        firstnode.position.x=this.spawn_positionx
                        firstnode.position.y=this.spawn_positiony
                        this.allnode.push(firstnode)
                        cc.tween(tnode).to(this.move_velocity,{position:cc.v3(this.spawn_positionx,this.spawn_positiony,0),scale:this.allnode[5].scale}).start()
                    }).start()
                }
                else if(i>0&&i<5)
                {
                    if(i==4)
                    {
                        //4右边进来,调整透明度
                        cc.tween(tnode).to(this.disappear_velocity+0.6,{opacity:255}).start()
                    }
                    let lastnode=this.allnode[i-1]
                    let lastnodep=lastnode.position
                    //数字移动到x-50,在回到x,抖动效果
                    cc.tween(tnode).to(this.move_velocity,{position:cc.v3(lastnodep.x-50,lastnodep.y,0),scale:lastnode.scale}).call(() => {
                        cc.tween(tnode).to(0.12,{position:cc.v3(lastnodep.x,lastnodep.y,0)}).call(() => {
                            //中间是6时播放咬动,同时果子移动
                            // if(i==3&&tnode.getComponent(cc.RichText).string=="6"){
                            //     this.getComponent(gif).moveToNextFrame(5,8,0)
                            //     this.node.getChildByName("xgcol").getComponent(xgcol).richtextmove(nextxg)//果子移动,nextxg是新果子的效果
                            // }
                        }).start()
                    }).start()
                    tnode.opacity=0
                    //颜色没用的
                    cc.tween(tnode).to(this.move_velocity,{color:lastnode.color}).start()
                    //透明度
                    cc.tween(tnode).to(this.disappear_velocity+0.6,{opacity:255}).start()
                }
            }
            //去掉最左边的数字,前面i=0时已经把他push到最右边了
            this.allnode=this.allnode.slice(1)
    }
}
